#!/bin/bash
###SHELLPACK preamble hpcc-install 1.5.0
WEB_LOCATION="http://icl.cs.utk.edu/projectsfiles/hpcc/download"
MIRROR_LOCATION="$WEBROOT/hpcc/"

install-depends openmpi openmpi-devel openmpi-libs libblas3 blas blas-devel blas-devel-static
install-depends libpsm_infinipath1

###SHELLPACK parseargBegin
###SHELLPACK parseargEnd

TEMPLATE=Linux_PII_CBLAS

template_set_param() {
	KEY=$1
	VALUE=$2
	VALUE_ESCAPED=`echo "$VALUE" | sed -e 's/\//\\\\\//g'`
	sed -i -e "s/$KEY\s*=.*/$KEY = $VALUE_ESCAPED/" Make.$TEMPLATE
}

###SHELLPACK sources_fetch hpcc-${VERSION}.tar.gz hpcc-$VERSION-installed
###SHELLPACK build_start hpcc-${VERSION}-installed
cd hpl || die Package is not laid out as expected
cp setup/Make.$TEMPLATE . || die Failed to copy $TEMPLATE template
template_set_param MPdir  $HPCC_MPI_PATH
template_set_param MPlib  ""
template_set_param LAdir  /usr/$MMTESTS_LIBDIR
template_set_param LAinc  -I/usr/include
template_set_param LAlib  -lblas
template_set_param CC     $HPCC_MPI_PATH/mpicc
template_set_param LINKER $HPCC_MPI_PATH/mpicc
sed -i -e /HPL_CALL_CBLAS/d Make.$TEMPLATE

make arch=$TEMPLATE || die Failed to build hpcc stage 1
cd ..
make arch=$TEMPLATE
if [ $? -ne 0 ]; then
	###SHELLPACK self_extract fix-restrict.patch
	cat $SHELLPACK_TEMP/fix-restrict.patch | patch -p1 || die Failed to apply restrict keyword fix
	make arch=$TEMPLATE || die Failed to build hpcc stage 2
fi

exit $SHELLPACK_SUCCESS

==== BEGIN fix-restrict.patch ====
diff --git a/STREAM/stream.c b/STREAM/stream.c
index 87aceed..a56fed9 100644
--- a/STREAM/stream.c
+++ b/STREAM/stream.c
@@ -175,7 +175,7 @@ static int array_elements;
 # define HLINE "-------------------------------------------------------------\n"
 
 /* Some compilers require an extra keyword to recognize the "restrict" qualifier. */
-static double * restrict a, * restrict b, * restrict c;
+static double * __restrict__ a, * __restrict__ b, * __restrict__ c;
 
 static double avgtime[4] = {0}, maxtime[4] = {0},
   mintime[4] = {FLT_MAX,FLT_MAX,FLT_MAX,FLT_MAX};
==== END fix-restrict.patch ====

